<?php

    define( 'WALL_LEFT_LIMIT', 30 );
	define( 'WALL_TOP_LIMIT', 30 );
	define( 'STYLE_COUNT', 8 );
	define( 'IMAGE_COUNT', 15 );
	define( 'WALL_PAD_TEMPLATE', '<div class="wall" style="z-index:{0};left:{1}px;top:{2}px;"><div class="top-{3}"><span class="x">×</span>第[{0}]条&nbsp;&nbsp;{4}</div><div class="mid-{3}"><span class="wt"><b>{5}</b>：</span><span>{6}</span></div><div class="bot-{3}"><img src="images/style/{7}.gif" alt="" /><span class="inline">{8}</span></div></div>' );

	function reload()
    {
		//echo('<script type="text/javascript">window.location.replace(\'default.php?w=\' + window.screen.availWidth + \'&h=\' + window.screen.availHeight);</script>');
		echo('<script type="text/javascript">window.location.replace(\'default.php?w=940&h=\' + window.screen.availHeight);</script>');
		die();
	}

    require_once('../wp-config.php');

    class Pad
    {
        private function apply_filter($str)
        {
            if(!get_magic_quotes_gpc())
            {
                $str = addslashes($str);
            }

            return htmlspecialchars($str);
        }

        function post($wishTo, $wishFrom, $wish)
        {
            global $wpdb;

            $wpdb->query( $wpdb->prepare("INSERT INTO wish (wFrom, wTo, wish, wStyleIndex, wImageIndex) VALUES (%s, %s, %s, %d, %d)",
                $this->apply_filter($wishFrom), $this->apply_filter($wishTo), $this->apply_filter($wish), rand(1, STYLE_COUNT), rand(1, IMAGE_COUNT)
            ) );
        }

        function toHTML($screenWidth, $screenHeight)
        {
            global $wpdb;
            $rs = (array) $wpdb->get_results('SELECT wFrom, wTo, wish, wTime, wStyleIndex, wImageIndex FROM wish ORDER BY wID ASC', ARRAY_N);
            $i = 1;

            foreach ($rs as $row)
            {
                $padleft = rand(1, $screenWidth - 250 - WALL_LEFT_LIMIT);
                $padtop = rand(WALL_TOP_LIMIT, $screenHeight - 350 - WALL_TOP_LIMIT);

                $strTemp = str_replace('{0}', strval($i), WALL_PAD_TEMPLATE);
                $strTemp = str_replace('{1}', strval($padleft), $strTemp);
                $strTemp = str_replace('{2}', strval($padtop), $strTemp);
                $strTemp = str_replace('{3}', $row[4], $strTemp);
                $strTemp = str_replace('{4}', $row[3], $strTemp);
                $strTemp = str_replace('{5}', $row[1], $strTemp);
                $strTemp = str_replace('{6}', $row[2], $strTemp);
                $strTemp = str_replace('{7}', $row[5], $strTemp);
                $strTemp = str_replace('{8}', $row[0], $strTemp);

                echo ($strTemp);

                $i++;
            }
        }
    }
?>